<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: checkout_payment.php 159 2013-09-22 07:53:18Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 159 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 07:53:18 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright(c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

include('includes/application_top.php');

if(CHECKOUT_AJAX_STAT == 'true')
	redirect(href_link(FILENAME_CHECKOUT,(isset($_GET['error_message']) ? 'error_massage='.$_GET['error_message'] : ''), 'SSL'));

$smarty = new Smarty();

require(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/source/boxes.php');
$smarty->assign('language', $_SESSION['language']);

require_once(DIR_FS_INC.'inc.address_label.php');
require_once(DIR_FS_INC.'inc.get_address_format_id.php');
require_once(DIR_FS_INC.'inc.check_stock.php');
unset($_SESSION['tmp_oID']);
unset($_SESSION['transaction_id']);
unset($_SESSION['all_checkout_checks_ok']);

if(!isset($_SESSION['customer_id'])) {
	if(ACCOUNT_OPTIONS == 'guest')
		redirect(href_link(FILENAME_CREATE_GUEST_ACCOUNT, '', 'SSL'));
	else
		redirect(href_link(FILENAME_LOGIN, '', 'SSL'));
}

if($_SESSION['cart']->count_contents() < 1)
	redirect(href_link(FILENAME_SHOPPING_CART));

if(!isset($_SESSION['shipping']))
	redirect(href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));

// avoid hack attempts during the checkout procedure by checking the internal cartID
if(isset($_SESSION['cart']->cartID) && isset($_SESSION['cartID'])) {
	if($_SESSION['cart']->cartID != $_SESSION['cartID'])
		redirect(href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
}

checkout_site('payment');

if(isset($_SESSION['credit_covers']))
	unset($_SESSION['credit_covers']);

if((STOCK_CHECK == 'true') &&(STOCK_ALLOW_CHECKOUT != 'true')) {
	$products = $_SESSION['cart']->get_products();
	$any_out_of_stock = 0;
	for($i = 0, $n = sizeof($products); $i < $n; $i++) {
		if(check_stock($products[$i]['id'], $products[$i]['quantity']))
			$any_out_of_stock = 1;
	}
	if($any_out_of_stock == 1)
		redirect(href_link(FILENAME_SHOPPING_CART));
}

if(!isset($_SESSION['billto']))
	$_SESSION['billto'] = $_SESSION['customer_default_address_id'];
	
else {
	$check_address = $db->db_query("SELECT 
										count(*) AS total 
									FROM 
										".TABLE_ADDRESS_BOOK." 
									WHERE 
										customers_id = '".(int)$_SESSION['customer_id']."' 
									AND 
										address_book_id = '".(int) $_SESSION['billto']."'");

	if($check_address->fields['total'] != '1') {
		$_SESSION['billto'] = $_SESSION['customer_default_address_id'];
		if(isset($_SESSION['payment']))
			unset($_SESSION['payment']);
	}
}

if(!isset($_SESSION['sendto']) || $_SESSION['sendto'] == "")
	$_SESSION['sendto'] = $_SESSION['billto'];

require(DIR_WS_CLASSES.'class.order.php');
$order = new order();

require(DIR_WS_CLASSES.'class.order_total.php');
$order_total_modules = new order_total();

$total_weight = $_SESSION['cart']->show_weight();

$total_count = $_SESSION['cart']->count_contents_virtual(); // GV Code ICW ADDED FOR CREDIT CLASS SYSTEM

if($order->billing['country']['iso_code_2'] != '' && $order->delivery['country']['iso_code_2'] == '')
	$_SESSION['delivery_zone'] = $order->billing['country']['iso_code_2'];
else
	$_SESSION['delivery_zone'] = $order->delivery['country']['iso_code_2'];

require(DIR_WS_CLASSES.'class.payment.php');
$payment_modules = new payment;

$order_total_modules->process();

$breadcrumb->add(NAVBAR_TITLE_1_CHECKOUT_PAYMENT, href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
$breadcrumb->add(NAVBAR_TITLE_2_CHECKOUT_PAYMENT, href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));

$smarty->assign('FORM_ACTION', draw_form('checkout_payment', href_link(FILENAME_CHECKOUT_CONFIRMATION, '', 'SSL'), 'post', 'onSubmit="return check_form();"'));
$smarty->assign('ADDRESS_LABEL', address_label($_SESSION['customer_id'], $_SESSION['billto'], true, ' ', '<br />'));
$smarty->assign('BUTTON_ADDRESS', '<a href="'.href_link(FILENAME_CHECKOUT_PAYMENT_ADDRESS, '', 'SSL').'">'.image_button('button_change_address.gif', IMAGE_BUTTON_CHANGE_ADDRESS).'</a>');
$smarty->assign('BUTTON_CONTINUE', image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE));
$smarty->assign('FORM_END', '</form>');

require(DIR_WS_INCLUDES.'header.php');
$module_smarty = new Smarty;

if($order->info['total'] > 0) {
	if(isset($_SESSION['error_message']))
	   $smarty->assign('error', urldecode($_SESSION['error_message']));
	
	if(isset($_GET['payment_error']) && is_object(${ $_GET['payment_error'] }) &&($error = ${$_GET['payment_error']}->get_error()))
	   $smarty->assign('error', htmlspecialchars($error['error']));
	
	if(isset($_SESSION['reshash']['FORMATED_ERRORS']))
	$smarty->assign('error', $_SESSION['reshash']['FORMATED_ERRORS']);

	$selection = $payment_modules->selection();

	$radio_buttons = 0;
	for($i = 0, $n = sizeof($selection); $i < $n; $i++) {

		$selection[$i]['radio_buttons'] = $radio_buttons;
		if(($selection[$i]['id'] == $payment) ||($n == 1))
			$selection[$i]['checked'] = 1;

		if(sizeof($selection) > 1) {
			$selection[$i]['selection'] = draw_radio_field('payment', $selection[$i]['id'],($selection[$i]['id'] == $_SESSION['payment']),'class="checkout_payment_input"');
			if($selection[$i]['id'] == $_SESSION['payment'])
				$selection[$i]['checked'] = true;
			else
				$selection[$i]['checked'] = false;
		} else
			$selection[$i]['selection'] = draw_hidden_field('payment', $selection[$i]['id'],'','class="checkout_payment_input"');

		if(isset($selection[$i]['error'])) {

		} else
			$radio_buttons++;
	}

	$module_smarty->assign('module_content', $selection);

} else
	$smarty->assign('GV_COVER', 'true');

unset($_SESSION['reshash']);
unset($_SESSION['nvpReqArray']);

if(ACTIVATE_GIFT_SYSTEM == 'true')
	$smarty->assign('module_gift', $order_total_modules->credit_selection());

$module_smarty->caching = false;
$payment_block = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/checkout_payment_block.html');

$smarty->assign('COMMENTS', draw_textarea_field('comments', 'soft', '60', '5', $_SESSION['comments']).draw_hidden_field('comments_added', 'YES'));

if(DISPLAY_CONDITIONS_ON_CHECKOUT == 'true') {
	if(GROUP_CHECK == 'true')
		$group_check = " AND group_ids LIKE '%c_".$_SESSION['customers_status']['customers_status_id']."_group%'";
	
	$shop_content_data = $db->db_query("SELECT
											content_title,
											content_heading,
											content_text,
											content_file
										FROM 
											".TABLE_CONTENT_MANAGER."
										WHERE 
											content_group='3' ".$group_check."
										AND 
											languages_id='".$_SESSION['languages_id']."'");
	
	if($shop_content_data->fields['content_file'] != '') {
		if($shop_content_data->fields['content_file'] == 'janolaw_agb.php') {
			include(DIR_FS_INC.'inc.janolaw.php');
			$conditions = JanolawContent('agb', 'txt');
		} else
			$conditions = '<iframe src="'.DIR_WS_CATALOG.'media/content/'.$shop_content_data->fields['content_file'].'" width="100%" height="300"></iframe>';
	} else
		$conditions = '<div class="div_textarea">'.$shop_content_data->fields['content_text'].'</div>';
	
	$smarty->assign('AGB_checkbox', '<input type="checkbox" value="conditions" name="conditions" />');
	$smarty->assign('AGB', $conditions);
	$smarty->assign('AGB_LINK', $main->getContentLink(3, MORE_INFO));
	$smarty->assign('BUTTON_PRINT_AGB', '(<a style="cursor:pointer" onclick="javascript:window.open(\''.href_link(FILENAME_PRINT_CONTENT, 'coID=3').'\', \'popup\', \'toolbar=0, width=640, height=600\')">'.PRINT_CONTENT.'</a>');
	$smarty->assign('AGB_PDF_LINK','<a href="'.href_link(FILENAME_PRINT_PDF,'content=3').'">'.image('images/button_pdf.gif',IMAGE_BUTTON_PRINT_PDF).'</a>)');
}
if(DISPLAY_DATENSCHUTZ_ON_CHECKOUT == 'true') {
	$smarty->assign('DS_checkbox', '<input type="checkbox" value="datenschutz" name="datenschutz" />');
	$smarty->assign('BUTTON_PRINT_DS', '(<a style="cursor:pointer" onclick="javascript:window.open(\''.href_link(FILENAME_PRINT_CONTENT, 'coID=2').'\', \'popup\', \'toolbar=0, width=640, height=600\')">'.PRINT_CONTENT.'</a>');
	$smarty->assign('DS_PDF_LINK','<a href="'.href_link(FILENAME_PRINT_PDF,'content=2').'">'.image('images/button_pdf.gif',IMAGE_BUTTON_PRINT_PDF).'</a>)');
}

if(DISPLAY_WIDERRUFSRECHT_ON_CHECKOUT == 'true') {
       $smarty->assign('WD_checkbox', '<input type="checkbox" value="widerrufsrecht" name="widerrufsrecht" />');
       $smarty->assign('BUTTON_PRINT_WD', '(<a style="cursor:pointer" onclick="javascript:window.open(\''.href_link(FILENAME_PRINT_CONTENT, 'coID=10').'\', \'popup\', \'toolbar=0, width=640, height=600\')">'.PRINT_CONTENT.'</a>');
       $smarty->assign('WD_PDF_LINK','<a href="'.href_link(FILENAME_PRINT_PDF,'content=10').'">'.image('images/button_pdf.gif',IMAGE_BUTTON_PRINT_PDF).'</a>)');
}

$smarty->assign('language', $_SESSION['language']);
$smarty->assign('PAYMENT_BLOCK', $payment_block);
$smarty->caching = false;
$main_content = $smarty->fetch(CURRENT_TEMPLATE.'/module/checkout_payment.html');

$smarty->assign('language', $_SESSION['language']);
$smarty->assign('main_content', $main_content);
$smarty->caching = false;
if(!defined('RM'))
	$smarty->loadFilter('output', 'note');
$smarty->loadFilter('output','trimwhitespace');
$smarty->display(CURRENT_TEMPLATE.'/index.html');
include('includes/application_bottom.php');
?>